﻿@using Orchard.DisplayManagement.Shapes
@using Orchard.DynamicForms.Elements
@using Orchard.Layouts.Helpers
@{
    var element = (TextArea)Model.Element;
    var tagBuilder = (OrchardTagBuilder)TagBuilderExtensions.CreateElementTagBuilder(Model, "textarea");
    var name = !String.IsNullOrWhiteSpace((string) Model.ProcessedName) ? (string)Model.ProcessedName : "TextArea1";

    tagBuilder.AddCssClass("text");
    tagBuilder.Attributes["name"] = name;
    tagBuilder.AddClientValidationAttributes((IDictionary<string, string>)Model.ClientValidationAttributes);

    if (element.Rows != null) {
        tagBuilder.Attributes["rows"] = element.Rows.ToString();
    }

    if (element.Columns != null) {
        tagBuilder.Attributes["cols"] = element.Columns.ToString();
    }

    if (!ViewData.ModelState.IsValidField(name)) {
        tagBuilder.AddCssClass("input-validation-error");
    }

    if (!String.IsNullOrWhiteSpace((string)Model.ProcessedValue)) {
        tagBuilder.SetInnerText(Model.ProcessedValue);
    }
}
@if (element.ShowLabel) {
    <label for="@element.HtmlId">@Model.ProcessedLabel</label>
}

@tagBuilder.ToHtmlString(TagRenderMode.Normal)
@if (element.ValidationSettings.ShowValidationMessage == true) {
    @Html.ValidationMessage(name)
}